﻿@model RegisterEditModel
@{
    var codeError = TempData.Get<string>("codeError", string.Empty);
}
<div class="panel-body ">
    <div class="col-xs-11">
        @using (Html.BeginForm("_ChangeEmail", "UserSpace", FormMethod.Post, new { @id = "ChangeEmailForm", @class = " form-horizontal tn-form-validation " }))
            {
            @Html.AntiForgeryToken()
            <div class="form-group">
                @Html.LabelFor(n => n.AccountEmail)
                @Html.TextBoxFor(n => n.AccountEmail, new { @class = "form-control" })
                @Html.ValidationMessageFor(n => n.AccountEmail)
            </div>
            <div class="form-group">
                <button type="button" id="changeSubmit" class="btn btn-primary tn-btn-wp">确定</button>
            </div>
        }
    </div>
</div>
<script type="text/javascript">
    require(['jquery', 'tnlayer'], function ($, tnlayer) {
   
    $("#changeSubmit").click(function myfunction() {
        var time = new Date().getTime();
        $("#ChangeEmailForm").validate();
        if ($("#ChangeEmailForm").valid()) {
            $.post("@CachedUrlHelper.Action("_ChangeEmail", "UserSpace")", $("#ChangeEmailForm").serialize(), function myfunction(data) {
                if (data.state == 1) {
                    layer.msg(data.msg, {
                        icon: 1
                    });
                    $.get("@SiteUrls.Instance()._UserProfile()", { t: time }, function myfunction(data) {
                        $("#gengxin").html(data);
                    });
                    window.setTimeout(function myfunction() {
                        layer.closeAll();
                    }, 2000)

                } else {
                    layer.msg(data.msg, {
                        icon: 2
                    });
                }
            })
        }
    });

    $("#getCode").click(function myfunction() {
        var time = new Date().getTime();
        var phone = $("#AccountMobile").val();
        var captchaInputText = $("#CaptchaInputText").val();
        var captchaDeText = $("#CaptchaDeText").val();
        $.post("@CachedUrlHelper.Action("SMSSend", "Account")", { captchaInputText: captchaInputText, captchaDeText: captchaDeText, phone: phone, type: 0 }, function myfunction(data) {
            if (data == 1) {
                layer.msg("发送成功,请注意查收", {
                    icon: 1
                });
                GetNumber();
            } else {
                layer.msg(data, {
                    icon: 2
                });

            }
        })
    });

    //倒计时
    var count = 60;
    function GetNumber() {
        $("#getCode").attr("disabled", "disabled");
        $("#getCode").val(count + "秒之后再次获取")
        count--;
        if (count >= 0) {
            setTimeout(GetNumber, 1000);
        }
        else {
            $("#getCode").val("免费获取短信激活码");
            $("#getCode").removeAttr("disabled");
            count = 60;
        }
    };
    })
</script>